package com.hzt.system.common;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
*
*
* @Author:hzt
* @Date:11:48 下午 2020/7/21
*/

/**
 *当实现此接口时，IOC容器初始化会回调setApplicationContext 把IOC容器对象转到里面了
 */
@Component
public class AppUtils implements ApplicationContextAware {

    public static ApplicationContext context;
    public static ApplicationContext getContext(){
        return context;
    }

    /**
     * 此处的applicationContext就是ioc容器
     * @param applicationContext
     * @throws BeansException
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            context=applicationContext;
    }
}
